package com.wnxy.sdd.front.controller;

import com.wnxy.sdd.front.service.ICourseService;
import com.wnxy.sdd.front.vo.IndexCourseQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private ICourseService courseService;

    // 通过@Value注解获取配置文件值
    @Value("${index.newCourseNum}")
    private Integer newCourseNum;

    /**
     * 转发到templates/index.html页面
     */
    @GetMapping("/index")
    public String index(Model model){

        // 新课上线
        List<IndexCourseQueryVo> newCourseList = courseService.queryNewCourse(newCourseNum);
        // 保存查询结果到request域
        model.addAttribute("newCourseList",newCourseList);

        // 对应templates下的index.html页面
        return "index";
    }
}
